package zozopo.manual.operations;


import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import zozopo.database.BusiDatabaseManager;
import zozopo.database.SqlMachine;
import zozopo.operations.comm.DictionaryOS;
import zozopo.operations.comm.OperatingService;

public class ReleaseOS extends OperatingService{
private static final Log logger = LogFactory.getLog(ReleaseOS.class);
	
	public ReleaseOS(Connection conn){
		super(conn);
		
	}
	
	public ReleaseOS(){
		this.databaseConnection = new BusiDatabaseManager();
		this.conn = databaseConnection.getConnection();
	}
	/**
	 * @version 1.0
	 * @param ReleaseTB release
	 * @author Shea
	 * @return boolean  
	 * @throws IOException 
	 * @see insertRelease(ImageTB image)
	 */
	public boolean insertRelease(ReleaseTB release){
		SqlMachine sqlMachine = new SqlMachine(conn);
		HashMap<String, Object> insertMap = new HashMap<String, Object>();
		
		insertMap.put(ReleaseTB.RELEASE_IP, release.getRelease_ip());
		insertMap.put(ReleaseTB.RELEASE_SUBJECT, release.getRelease_subject());
		insertMap.put(ReleaseTB.RELEASE_LABLE, release.getRelease_lable());
		insertMap.put(ReleaseTB.RELEASE_FROM, release.getRelease_from());
		insertMap.put(ReleaseTB.RELEASE_KIND, release.getRelease_kind());
		insertMap.put(ReleaseTB.RELEASE_URL, release.getRelease_url());
		insertMap.put(ReleaseTB.RELEASE_USERMEAIL, release.getRelease_useremail());
		insertMap.put(ReleaseTB.RELEASE_CONTEXT, release.getRelease_context());
		insertMap.put(ReleaseTB.RELEASE_BRAND, release.getRelease_brand());
		insertMap.put(ReleaseTB.RELEASE_SECONDBRAND, release.getRelease_secondbrand());
		insertMap.put(ReleaseTB.RELEASE_MD_DATE, new StringBuffer("now()"));
		

		return sqlMachine.insertRow(ReleaseTB.TABLE_NAME, insertMap);
	}
	
	/**
	 * @version 1.0
	 * @param ReleaseTB release
	 * @author Shea
	 * @return boolean  
	 * @throws IOException 
	 * @see insertRelease(ImageTB image)
	 */
	public boolean upadteRelease(ReleaseTB release){
		SqlMachine sqlMachine = new SqlMachine(conn);
		HashMap<String, Object> updateMap = new HashMap<String, Object>();
		
		updateMap.put(ReleaseTB.RELEASE_IP, release.getRelease_ip());
		updateMap.put(ReleaseTB.RELEASE_SUBJECT, release.getRelease_subject());
		updateMap.put(ReleaseTB.RELEASE_LABLE, release.getRelease_lable());
		updateMap.put(ReleaseTB.RELEASE_CONTEXT, release.getRelease_context());
		updateMap.put(ReleaseTB.RELEASE_BRAND, release.getRelease_brand());
		updateMap.put(ReleaseTB.RELEASE_SECONDBRAND, release.getRelease_secondbrand());
		updateMap.put(ReleaseTB.RELEASE_KIND, release.getRelease_kind());
		updateMap.put(ReleaseTB.RELEASE_URL, release.getRelease_url());
		updateMap.put(ReleaseTB.RELEASE_IMAGE, release.getRelease_image());
		updateMap.put(ReleaseTB.RELEASE_MD_DATE, new StringBuffer("now()"));
		
		return sqlMachine.updateRow(ReleaseTB.TABLE_NAME, updateMap, ReleaseTB.RELEASE_ID, release.getRelease_id());
	}
	
	/**
	 * @version 1.0
	 * @param ReleaseTB release
	 * @author Shea
	 * @return boolean  
	 * @throws IOException 
	 * @see 更新网店URL到主题内容当中
	 */
	public boolean upadteRecommendUrlToContext(int id){
		SqlMachine sqlMachine = new SqlMachine(conn);
		String context = "<a href=view.action?id="+id+"&from=REMOTE target=_blank>点击进入此网店</a><br>";
		
		return sqlMachine.updateRow(ReleaseTB.TABLE_NAME, ReleaseTB.RELEASE_ID, id, ReleaseTB.RELEASE_CONTEXT, context);
	}
	/**
	 * @version 1.0
	 * @param String pageSize
	 * @author Shea
	 * @return boolean  
	 * @throws IOException 
	 * @see selectNewRelease(ImageTB image)
	 */
	public int getMaxIdByEmail(String email){
		//String sql = "select * from "+ReleaseTB.TABLE_NAME+" order by  "+ReleaseTB.RELEASE_DATE+" desc limit "+beginPageNum+","+pageSize; 
		SqlMachine sqlMachine = new SqlMachine(conn);
		int maxId = sqlMachine.getMaxId(ReleaseTB.RELEASE_ID, ReleaseTB.TABLE_NAME, ReleaseTB.RELEASE_USERMEAIL, email);
		return maxId;
	}
	
	/**
	 * @version 1.0
	 * @param String pageSize
	 * @author Shea
	 * @return boolean  
	 * @throws IOException 
	 * @see selectNewRelease(ImageTB image)
	 */
	public List<ReleaseTB> selectNewRelease(int beginPageNum,int pageSize){
		
		String sql = "select * from "+ReleaseTB.TABLE_NAME+" order by  "+ReleaseTB.RELEASE_DATE+" desc limit "+beginPageNum+","+pageSize; 
	
		return selectReleaseListBySqlNoContent(sql);
	}
	
	/**
	 * @version 1.0
	 * @param String pageSize
	 * @author Shea
	 * @return boolean  
	 * @throws IOException 
	 * @see selectNewRelease(ImageTB image)
	 */
	public List<ReleaseTB> selectNewReleaseNoContent(int beginPageNum,int pageSize){
		
		String sql = "select * from "+ReleaseTB.TABLE_NAME+" order by  "+ReleaseTB.RELEASE_DATE+" desc limit "+beginPageNum+","+pageSize; 
		
		return selectReleaseListBySqlNoContent(sql);
	}
	
	/**
	 * @version 1.0
	 * @param String pageSize
	 * @author Shea
	 * @return boolean  
	 * @throws IOException 
	 * @see selectNewRelease(ImageTB image)
	 */
	public ReleaseTB getSubjectById(int subjectId){
		ReleaseTB release = null;
		
		String sql = "select * from "+ReleaseTB.TABLE_NAME+" where "+ReleaseTB.RELEASE_ID+"="+subjectId;
		DictionaryOS dictionaryOS= new DictionaryOS(conn);
		
		if(logger.isDebugEnabled()){
			logger.debug("getUserInfoByName() sql:"+sql.toString());
		}
		ResultSet resultSet = databaseConnection.executeQuery(conn,sql);
		
		System.out.println(sql);
		try {
			if(resultSet.next()){
				release = new ReleaseTB();
				release.setRelease_id(resultSet.getString(ReleaseTB.RELEASE_ID));
				release.setRelease_brand(resultSet.getString(ReleaseTB.RELEASE_BRAND));
				release.setRelease_secondbrand(resultSet.getString(ReleaseTB.RELEASE_SECONDBRAND));
				release.setRelease_context(resultSet.getString(ReleaseTB.RELEASE_CONTEXT));
				release.setRelease_date(resultSet.getString(ReleaseTB.RELEASE_DATE));
				release.setRelease_des(resultSet.getString(ReleaseTB.RELEASE_DES));
				release.setRelease_key(resultSet.getString(ReleaseTB.RELEASE_KEY));
				release.setRelease_lable(resultSet.getString(ReleaseTB.RELEASE_LABLE));
				release.setRelease_labledicvalue(dictionaryOS.getDictValue(release.getRelease_lable()));
				release.setRelease_md_date(resultSet.getString(ReleaseTB.RELEASE_MD_DATE));
				release.setRelease_subject(resultSet.getString(ReleaseTB.RELEASE_SUBJECT));
				release.setRelease_url(resultSet.getString(ReleaseTB.RELEASE_URL));
				release.setRelease_ip(resultSet.getString(ReleaseTB.RELEASE_IP));
				release.setRelease_useremail(resultSet.getString(ReleaseTB.RELEASE_USERMEAIL));
				release.setRelease_state(resultSet.getString(ReleaseTB.RELEASE_STATE));
				release.setRelease_from(resultSet.getString(ReleaseTB.RELEASE_FROM));
				release.setRelease_kind(resultSet.getString(ReleaseTB.RELEASE_KIND));
				release.setRelease_kindvalue(dictionaryOS.getDictValue(release.getRelease_kind()));
				release.setRelease_image(resultSet.getString(ReleaseTB.RELEASE_IMAGE));
				
				release.setRelease_bear(resultSet.getInt(ReleaseTB.RELEASE_BEAR));
				release.setRelease_replys(resultSet.getInt(ReleaseTB.RELEASE_REPLYS));
				release.setRelease_views(resultSet.getInt(ReleaseTB.RELEASE_VIEWS));
				
				try {
					release.setEncodebrand(java.net.URLEncoder.encode(release.getRelease_brand(),"utf-8").replaceAll("%", "%25"));
				} catch (UnsupportedEncodingException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
			}
			resultSet.close();
		} catch (SQLException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
		}
		return release;
}
		
	/**
	 * @version 1.0
	 * @param String brand
	 * @author Shea
	 * @return ResultSet  
	 * @throws IOException 
	 * @see 热门主题显示
	 */
	public List<ReleaseTB> selectRelatedForHit(int lastDay,int beginPageNum,int pageSize){
		List<ReleaseTB> hitList = null;
	
		String sql = "select * from "+ReleaseTB.TABLE_NAME+" where "+ReleaseTB.RELEASE_DATE+" >= date_add(now(), interval "+lastDay+" day) order by "+ReleaseTB.RELEASE_VIEWS+" desc limit "+beginPageNum+","+pageSize; 
		if(logger.isDebugEnabled()){
			logger.debug("getUserInfoByName() sql:"+sql.toString());
		}
		
		hitList = selectReleaseListBySql(sql);
		
		return hitList;
	}	
	
	/**
	 * @version 1.0
	 * @param String brand
	 * @author Shea
	 * @return ResultSet  
	 * @throws IOException 
	 * @see 热门主题显示
	 */
	public List<ReleaseTB> selectRelatedForHitNoContent(int lastDay,int beginPageNum,int pageSize){
		List<ReleaseTB> hitList = null;
	
		String sql = "select * from "+ReleaseTB.TABLE_NAME+" where "+ReleaseTB.RELEASE_DATE+" >= date_add(now(), interval "+lastDay+" day) order by "+ReleaseTB.RELEASE_VIEWS+" desc limit "+beginPageNum+","+pageSize; 
		if(logger.isDebugEnabled()){
			logger.debug("getUserInfoByName() sql:"+sql.toString());
		}
		
		hitList = selectReleaseListBySqlNoContent(sql);
		
		return hitList;
	}	
	
	/**
	 * @version 1.0
	 * @param String brand
	 * @author Shea
	 * @return ResultSet  
	 * @throws IOException 
	 * @see 通过标签显示热门主题
	 */
	public List<ReleaseTB> selectHitByLable(String lable,int lastDay,int beginPageNum,int pageSize){
		List<ReleaseTB> hitList = null;
	
		String sql = "select * from "+ReleaseTB.TABLE_NAME+" where "+ReleaseTB.RELEASE_DATE+" >= date_add(now(), interval "+lastDay+" day)" +
				" and " + ReleaseTB.RELEASE_LABLE +"='"+lable+
				"' order by "+ReleaseTB.RELEASE_VIEWS+" desc limit "+beginPageNum+","+pageSize; 
		if(logger.isDebugEnabled()){
			logger.debug("getUserInfoByName() sql:"+sql.toString());
		}
		
		hitList = selectReleaseListBySql(sql);
		
		return hitList;
	}
	
	/**
	 * @version 1.0
	 * @param String brand
	 * @author Shea
	 * @return ResultSet  
	 * @throws IOException 
	 * @see 通过标签显示热门主题
	 */
	public List<ReleaseTB> selectHitByLable(String lable,int beginPageNum,int pageSize){
		List<ReleaseTB> hitList = null;
	
		String sql = "select * from "+ReleaseTB.TABLE_NAME+" where " +
			    ReleaseTB.RELEASE_LABLE +"='"+lable+
				"' order by "+ReleaseTB.RELEASE_VIEWS+" desc limit "+beginPageNum+","+pageSize; 
		if(logger.isDebugEnabled()){
			logger.debug("getUserInfoByName() sql:"+sql.toString());
		}
		
		hitList = selectReleaseListBySql(sql);
		
		return hitList;
	}
	
	
	
	
	/**
	 * @version 1.0
	 * @param String brand
	 * @author Shea
	 * @return ResultSet  
	 * @throws IOException 
	 * @see 通过类型显示热门主题
	 */
	
	public List<ReleaseTB> selectHitByKind(String kind,int lastDay,int beginPageNum,int pageSize){
		List<ReleaseTB> hitList = null;
	
		String sql = "select * from "+ReleaseTB.TABLE_NAME+" where "+ReleaseTB.RELEASE_DATE+" >= date_add(now(), interval "+lastDay+" day)" +
				" and " + ReleaseTB.RELEASE_KIND +"='"+kind+
				"' order by "+ReleaseTB.RELEASE_VIEWS+" desc limit "+beginPageNum+","+pageSize; 
		if(logger.isDebugEnabled()){
			logger.debug("getUserInfoByName() sql:"+sql.toString());
		}
		
		hitList = selectReleaseListBySqlNoContent(sql);
		
		return hitList;
	}	
	
	/**
	 * @version 1.0
	 * @param String brand
	 * @author Shea
	 * @return ResultSet  
	 * @throws IOException 
	 * @see 通过类型显示热门主题
	 */
	
	public List<ReleaseTB> selectHitByKind(String kind,int beginPageNum,int pageSize){
		List<ReleaseTB> hitList = null;
	
		String sql = "select * from "+ReleaseTB.TABLE_NAME+" where " + ReleaseTB.RELEASE_KIND +"='"+kind+
				"' order by "+ReleaseTB.RELEASE_VIEWS+" desc limit "+beginPageNum+","+pageSize; 
		if(logger.isDebugEnabled()){
			logger.debug("getUserInfoByName() sql:"+sql.toString());
		}
		
		hitList = selectReleaseListBySqlNoContent(sql);
		
		return hitList;
	}	
	
	/**
	 * @version 1.0
	 * @param String brand
	 * @author Shea
	 * @return ResultSet  
	 * @throws IOException 
	 * @see 通过类型显示最新主题
	 */
	
	public List<ReleaseTB> selectNewByKind(String kind,int beginPageNum,int pageSize){
		List<ReleaseTB> hitList = null;
		
		String sql = "select * from "+ReleaseTB.TABLE_NAME+" where " + ReleaseTB.RELEASE_KIND +"='"+kind+
				"' order by "+ReleaseTB.RELEASE_DATE+" desc limit "+beginPageNum+","+pageSize; 
		if(logger.isDebugEnabled()){
			logger.debug("getUserInfoByName() sql:"+sql.toString());
		}
		
		hitList = selectReleaseListBySql(sql);
		
		return hitList;
	}	
	
	/**
	 * @version 1.0
	 * @param String brand
	 * @author Shea
	 * @return ResultSet  
	 * @throws IOException 
	 * @see 通过lable显示最新主题
	 */
	
	public List<ReleaseTB> selectNewByLable(String lable,int beginPageNum,int pageSize){
		List<ReleaseTB> hitList = null;
		
		String sql = "select * from "+ReleaseTB.TABLE_NAME+" where " + ReleaseTB.RELEASE_LABLE +"='"+lable+
				"' order by "+ReleaseTB.RELEASE_DATE+" desc limit "+beginPageNum+","+pageSize; 
		if(logger.isDebugEnabled()){
			logger.debug("getUserInfoByName() sql:"+sql.toString());
		}
		
		hitList = selectReleaseListBySqlLimitContent(sql);
		
		return hitList;
	}	
	
	/**
	 * @version 1.0
	 * @param String brand
	 * @author Shea
	 * @return ResultSet  
	 * @throws IOException 
	 * @see 通过类型及标签显示热门主题
	 */
	
	public List<ReleaseTB> selectHitByKindAndLable(String kind,String lable,int beginPageNum,int pageSize){
		List<ReleaseTB> hitList = null;
	
		String sql = "select * from "+ReleaseTB.TABLE_NAME+" where " + ReleaseTB.RELEASE_KIND +"='"+kind+
				"' and " + ReleaseTB.RELEASE_LABLE +"='"+lable+
				"' order by "+ReleaseTB.RELEASE_VIEWS+" desc limit "+beginPageNum+","+pageSize; 
		if(logger.isDebugEnabled()){
			logger.debug("getUserInfoByName() sql:"+sql.toString());
		}
		
		hitList = selectReleaseListBySqlNoContent(sql);
		
		return hitList;
	}	
	
	
	/**
	 * @version 1.0
	 * @param String brand
	 * @author Shea
	 * @return ResultSet  
	 * @throws IOException 
	 * @see 通过类型及标签显示热门主题
	 */
	
	public List<ReleaseTB> selectByKindAndLable(String kind,String lable,int beginPageNum,int pageSize){
		List<ReleaseTB> hitList = null;
	
		String sql = "select * from "+ReleaseTB.TABLE_NAME+" where " + ReleaseTB.RELEASE_KIND +"='"+kind+
				"' and " + ReleaseTB.RELEASE_LABLE +"='"+lable+
				"' "+" limit "+beginPageNum+","+pageSize; 
		if(logger.isDebugEnabled()){
			logger.debug("getUserInfoByName() sql:"+sql.toString());
		}
		
		hitList = selectReleaseListBySqlNoContent(sql);
		
		return hitList;
	}	
	
	/**
	 * @version 1.0
	 * @param String brand
	 * @author Shea
	 * @return ResultSet  
	 * @throws IOException 
	 * @see 通过类型及最新标签显示最新主题
	 */
	
	public List<ReleaseTB> selectNewByKindAndLable(String kind,String lable,int beginPageNum,int pageSize){
		List<ReleaseTB> hitList = null;
	
		String sql = "select * from "+ReleaseTB.TABLE_NAME+" where " + ReleaseTB.RELEASE_KIND +"='"+kind+
				"' and " + ReleaseTB.RELEASE_LABLE +"='"+lable+
				"' order by "+ReleaseTB.RELEASE_DATE+" desc limit "+beginPageNum+","+pageSize; 
		if(logger.isDebugEnabled()){
			logger.debug("getUserInfoByName() sql:"+sql.toString());
		}
		
		hitList = selectReleaseListBySql(sql);
		
		return hitList;
	}
	
	/**
	 * @version 1.0
	 * @param String brand
	 * @author Shea
	 * @return ResultSet  
	 * @throws IOException 
	 * @see 通过类型及最新标签显示最新主题
	 */
	
	public List<ReleaseTB> selectNewByBrandAndLable(String brand,String lable,int beginPageNum,int pageSize){
		List<ReleaseTB> hitList = null;
	  
		String sql = "select * from "+ReleaseTB.TABLE_NAME+" where (" + ReleaseTB.RELEASE_BRAND +" like '%"+brand+"%' or " 
				+ ReleaseTB.RELEASE_SECONDBRAND + " like '%"+brand+"%') " 
				+" and " + ReleaseTB.RELEASE_LABLE +"='"+lable+
				"' order by "+ReleaseTB.RELEASE_DATE+" desc limit "+beginPageNum+","+pageSize; 
		if(logger.isDebugEnabled()){
			logger.debug("getUserInfoByName() sql:"+sql.toString());
		}
		
		hitList = selectReleaseListBySql(sql);
		
		return hitList;
	}
	
	/**
	 * @version 1.0
	 * @param String brand
	 * @author Shea
	 * @return ResultSet  
	 * @throws IOException 
	 * @see 通过类型及最新标签显示最新主题
	 */
	
	public List<ReleaseTB> selectNewByBrandAndKind(String brand,String kind,int beginPageNum,int pageSize){
		List<ReleaseTB> hitList = null;
	
		String sql = "select * from "+ReleaseTB.TABLE_NAME+" where (" + ReleaseTB.RELEASE_BRAND +" like '%"+brand+
				
				"%' or " + ReleaseTB.RELEASE_SECONDBRAND + " like '%" + brand +
				
				"%') and " + ReleaseTB.RELEASE_KIND +"='" + kind + 
				
				"' order by "+ReleaseTB.RELEASE_DATE+" desc limit "+beginPageNum+","+pageSize; 
		if(logger.isDebugEnabled()){
			logger.debug("getUserInfoByName() sql:"+sql.toString());
		}
		
		hitList = selectReleaseListBySql(sql);
		
		return hitList;
	}
	
	/**
	 * @version 1.0
	 * @param String brand
	 * @author Shea
	 * @return ResultSet  
	 * @throws IOException 
	 * @see 通过类型及最新标签显示最新主题
	 */
	
	public List<ReleaseTB> selectNewByBrandAndKindAndLable(String brand,String kind,String lable,int beginPageNum,int pageSize){
		List<ReleaseTB> hitList = null;
	
		String sql = "select * from "+ReleaseTB.TABLE_NAME+" where (" + ReleaseTB.RELEASE_BRAND +" like '%"+brand+"%' or "
				+ ReleaseTB.RELEASE_SECONDBRAND + " like '%"+brand+"%') " 
				+ " and " + ReleaseTB.RELEASE_KIND +"='"+kind+
				"' and " + ReleaseTB.RELEASE_LABLE+"='"+lable+"' "+
				" order by "+ReleaseTB.RELEASE_DATE+" desc limit "+beginPageNum+","+pageSize; 
		if(logger.isDebugEnabled()){
			logger.debug("getUserInfoByName() sql:"+sql.toString());
		}
		
		hitList = selectReleaseListBySql(sql);
		
		return hitList;
	}
	
	/**
	 * @version 1.0
	 * @param String brand
	 * @author Shea
	 * @return ResultSet  
	 * @throws IOException 
	 * @see 热门产品显示
	 */
	public List<String> selectRelatedForBrandHit(int lastDay,int beginPageNum,int pageSize){
		
	
		String sql = "select distinct("+ReleaseTB.RELEASE_BRAND+") from "+ReleaseTB.TABLE_NAME+" where "+ReleaseTB.RELEASE_DATE+" >= date_add(now(), interval "+lastDay+" day) order by "+ReleaseTB.RELEASE_VIEWS+" desc limit "+beginPageNum+","+pageSize; 
		
		//select distinct(release_brand) from release_subject order by release_views desc
		if(logger.isDebugEnabled()){
			logger.debug("getUserInfoByName() sql:"+sql.toString());
		}
		List<String> releaseList = null;
		System.out.println(sql);
		ResultSet resultSet = databaseConnection.executeQuery(conn, sql);
		if(resultSet != null){
				try {
					releaseList = new ArrayList<String>();
					while(resultSet.next()){
						String brand =resultSet.getString(ReleaseTB.RELEASE_BRAND);
						releaseList.add(brand);
					}
					resultSet.close();
				} catch (SQLException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
		}
		
		return releaseList;
		
	}
	
	
	/**
	 * @version 1.0
	 * @param String brand
	 * @author Shea
	 * @return ResultSet  
	 * @throws IOException 
	 * @see 显示用户所有文章
	 */
	public List<ReleaseTB> selectReleaseByUsermail(String usermail,int beginPageNum,int pageSize){
		List<ReleaseTB> userReleaseList = null;
		String sql = "select * from "+ReleaseTB.TABLE_NAME +
		" where " +ReleaseTB.RELEASE_USERMEAIL + " = '"+usermail+"'" +" order by "+ReleaseTB.RELEASE_DATE+" desc limit "+beginPageNum+","+pageSize; 
		
		if(logger.isDebugEnabled()){
			logger.debug("getUserInfoByName() sql:"+sql.toString());
		}
		
		userReleaseList = selectReleaseListBySql(sql);
		
		return userReleaseList;
	}	
	
	/**
	 * @version 1.0
	 * @param String brand
	 * @author Shea
	 * @return ResultSet  
	 * @throws IOException 
	 * @see 通过类型热门显示产品
	 */
	public List<String> selectBrandHitByKind(String kind,int lastDay,int beginPageNum,int pageSize){
		
	
		String sql = "select distinct("+ReleaseTB.RELEASE_BRAND+") from "+ReleaseTB.TABLE_NAME+" where " + 
		ReleaseTB.RELEASE_LABLE + " ='"+kind+"' and "
		+ReleaseTB.RELEASE_DATE+" >= date_add(now(), interval "+lastDay+" day) order by "+ReleaseTB.RELEASE_VIEWS+" desc limit "+beginPageNum+","+pageSize; 
		
		//select distinct(release_brand) from release_subject order by release_views desc
		if(logger.isDebugEnabled()){
			logger.debug("getUserInfoByName() sql:"+sql.toString());
		}
		List<String> releaseList = null;
		//System.out.println(sql);
		ResultSet resultSet = databaseConnection.executeQuery(conn, sql);
		if(resultSet != null){
				try {
					releaseList = new ArrayList<String>();
					while(resultSet.next()){
						String brand =resultSet.getString(ReleaseTB.RELEASE_BRAND);
						releaseList.add(brand);
					}
					resultSet.close();
				} catch (SQLException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
		}
		
		return releaseList;
		
	}	
	
	/**
	 * @version 1.0
	 * @param String brand
	 * @author Shea
	 * @return ResultSet  
	 * @throws IOException 
	 * @see 通过类型热门显示产品
	 */
	public List<String> selectBrandHitByLable(String lable,int beginPageNum,int pageSize){
		
	
		String sql = "select distinct("+ReleaseTB.RELEASE_BRAND+") from "+ReleaseTB.TABLE_NAME+" where " + 
		ReleaseTB.RELEASE_LABLE + " ='"+lable+"'"
		+" order by "+ReleaseTB.RELEASE_VIEWS+" desc limit "+beginPageNum+","+pageSize; 
		
		//select distinct(release_brand) from release_subject order by release_views desc
		if(logger.isDebugEnabled()){
			logger.debug("getUserInfoByName() sql:"+sql.toString());
		}
		List<String> releaseList = null;
		//System.out.println(sql);
		ResultSet resultSet = databaseConnection.executeQuery(conn, sql);
		if(resultSet != null){
				try {
					releaseList = new ArrayList<String>();
					while(resultSet.next()){
						String brand =resultSet.getString(ReleaseTB.RELEASE_BRAND);
						releaseList.add(brand);
					}
					resultSet.close();
				} catch (SQLException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
		}
		
		return releaseList;
		
	}	
	
	/**
	 * @version 1.0
	 * @param String brand
	 * @author Shea
	 * @return ResultSet  
	 * @throws IOException 
	 * @see selectRelatedBrand(String brand,int beginPageNum,int pageSize)
	 */
	public List<ReleaseTB> selectRelatedBrand(String brand,int beginPageNum,int pageSize){
		List<ReleaseTB> brandList = null;
		String sql = "select * from "+ReleaseTB.TABLE_NAME 
		+ " where " + ReleaseTB.RELEASE_BRAND + " like '%"+brand+"%' or " 
		+ ReleaseTB.RELEASE_SECONDBRAND + " like '%"+brand+"%' " 
		+ " order by "+ReleaseTB.RELEASE_DATE+" desc limit "+beginPageNum+","+pageSize; 
		
		if(logger.isDebugEnabled()){
			logger.debug("getUserInfoByName() sql:"+sql.toString());
		}
		
		brandList = selectReleaseListBySqlLimitContent(sql);
		
		return brandList;
	}
	
	/**
	 * @version 1.0
	 * @param String brand
	 * @author Shea
	 * @return ResultSet  
	 * @throws IOException 
	 * @see selectRelatedBrand(String brand,int beginPageNum,int pageSize)
	 */
	public List<String> selectDistinctBrand(String brand,int beginPageNum,int pageSize){
		List<String> brandList = null;
		SqlMachine sqlMachine = new SqlMachine(conn);
		ResultSet resultSet = sqlMachine.distinctRecord(ReleaseTB.TABLE_NAME, ReleaseTB.RELEASE_BRAND);
		if(resultSet != null){
			try {
				brandList = new ArrayList<String>();
				while(resultSet.next()){
					ReleaseTB release = new ReleaseTB();
					
					String brandStr = resultSet.getString(ReleaseTB.RELEASE_BRAND);
					
					brandList.add(brandStr);
				}
				resultSet.close();
			} catch (SQLException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}
		return brandList;
	}
	
	
	
	/**
	 * @version 1.0
	 * @param String brand
	 * @author Shea
	 * @return ResultSet  
	 * @throws IOException 
	 * @see selectRelatedBrand(String brand,int beginPageNum,int pageSize)
	 */
	public List<ReleaseTB> saerchForJSON(String subject,int beginPageNum,int pageSize){
		List<ReleaseTB> brandList = null;
		String sql = "select * from "+ReleaseTB.TABLE_NAME +
		" where " +ReleaseTB.RELEASE_SUBJECT + " like '%"+subject+"%'" +" order by "+ReleaseTB.RELEASE_DATE+" desc limit "+beginPageNum+","+pageSize; 
		
		if(logger.isDebugEnabled()){
			logger.debug("getUserInfoByName() sql:"+sql.toString());
		}
		
		brandList = selectReleaseListBySql(sql);
		
		return brandList;
	}
	
	/**
	 * @version 1.0
	 * @param String brand
	 * @author Shea
	 * @return ResultSet  
	 * @throws IOException 
	 * @see selectRelatedBrand(String brand,int beginPageNum,int pageSize)
	 */
	public List<ReleaseTB> saerchBySubject(String subject,int beginPageNum,int pageSize){
		List<ReleaseTB> brandList = null;
		String sql = "select * from "+ReleaseTB.TABLE_NAME +
		" where " +ReleaseTB.RELEASE_SUBJECT + " like '%"+subject+"%'" +" order by "+ReleaseTB.RELEASE_DATE+" desc limit "+beginPageNum+","+pageSize; 
		
		if(logger.isDebugEnabled()){
			logger.debug("getUserInfoByName() sql:"+sql.toString());
		}
		
		brandList = selectReleaseListBySqlNoContent(sql);
		
		return brandList;
	}
	
	
	/**
	 * @version 1.0
	 * @param String brand
	 * @author Shea
	 * @return ResultSet  
	 * @throws IOException 
	 * @see 搜索类型
	 */
	public List<ReleaseTB> saerchByKind(String kind,int beginPageNum,int pageSize){
		List<ReleaseTB> brandList = null;
		String sql = "select * from "+ReleaseTB.TABLE_NAME +
		" where " +ReleaseTB.RELEASE_KIND + " = '"+kind+"'" +" order by "+ReleaseTB.RELEASE_DATE+" desc limit "+beginPageNum+","+pageSize; 
		
		if(logger.isDebugEnabled()){
			logger.debug("getUserInfoByName() sql:"+sql.toString());
		}
		
		brandList = selectReleaseListBySqlNoContent(sql);
		
		return brandList;
	}
	
	/**
	 * @version 1.0
	 * @param String brand
	 * @author Shea
	 * @return ResultSet  
	 * @throws IOException 
	 * @see 搜索类型
	 */
	public List<ReleaseTB> selectByKindForArea(String kind,int beginPageNum,int pageSize){
		List<ReleaseTB> brandList = null;
		String sql = "select * from "+ReleaseTB.TABLE_NAME +
		" where " +ReleaseTB.RELEASE_KIND + " = '"+kind+"'" +" order by "+ReleaseTB.RELEASE_DATE+" desc limit "+beginPageNum+","+pageSize; 
		
		if(logger.isDebugEnabled()){
			logger.debug("getUserInfoByName() sql:"+sql.toString());
		}
		
		DictionaryOS dictionaryOS= new DictionaryOS(conn);
		ResultSet resultSet = databaseConnection.executeQuery(conn, sql);
		
		if(resultSet != null){
				try {
					brandList = new ArrayList<ReleaseTB>();
					while(resultSet.next()){
						ReleaseTB release = new ReleaseTB();
						release.setRelease_id(resultSet.getString(ReleaseTB.RELEASE_ID));
						release.setRelease_brand(resultSet.getString(ReleaseTB.RELEASE_BRAND));
						release.setRelease_context(resultSet.getString(ReleaseTB.RELEASE_CONTEXT));
						
						String content = zozopo.comm.Validate.htmlLabelFilter(release.getRelease_context());
						content = zozopo.comm.Validate.htmlFilter(content);
						
						if(content.length() >=200 ){
							content = content.substring(0, 200) + "...";
						}
						release.setRelease_context(content);
						
						release.setRelease_date(resultSet.getString(ReleaseTB.RELEASE_DATE));
						release.setRelease_des(resultSet.getString(ReleaseTB.RELEASE_DES));
						release.setRelease_key(resultSet.getString(ReleaseTB.RELEASE_KEY));
						release.setRelease_lable(resultSet.getString(ReleaseTB.RELEASE_LABLE));
						
						release.setRelease_from(resultSet.getString(ReleaseTB.RELEASE_FROM));
						release.setRelease_kind(resultSet.getString(ReleaseTB.RELEASE_KIND));
						
						
						release.setRelease_md_date(resultSet.getString(ReleaseTB.RELEASE_MD_DATE));
						release.setRelease_subject(resultSet.getString(ReleaseTB.RELEASE_SUBJECT));
						release.setRelease_url(resultSet.getString(ReleaseTB.RELEASE_URL));
						release.setRelease_image(resultSet.getString(ReleaseTB.RELEASE_IMAGE)+"");
						release.setRelease_ip(resultSet.getString(ReleaseTB.RELEASE_IP));
						release.setRelease_useremail(resultSet.getString(ReleaseTB.RELEASE_USERMEAIL));
						release.setRelease_state(resultSet.getString(ReleaseTB.RELEASE_STATE));
						
						
						
						release.setRelease_bear(resultSet.getInt(ReleaseTB.RELEASE_BEAR));
						release.setRelease_replys(resultSet.getInt(ReleaseTB.RELEASE_REPLYS));
						release.setRelease_views(resultSet.getInt(ReleaseTB.RELEASE_VIEWS));
						
						release.setRelease_labledicvalue(dictionaryOS.getDictValue(release.getRelease_lable()));//为了显示
						release.setRelease_kindvalue(dictionaryOS.getDictValue(release.getRelease_kind()));//为了显示
						release.setRewriteUrl(getRewriteUrlToView(release.getRelease_id()));//为了显示
						
						brandList.add(release);
					}
					resultSet.close();
				} catch (SQLException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
		}
		
		
		return brandList;
	}
	/**
	 * @version 1.0
	 * @param String brand
	 * @author Shea
	 * @return ResultSet  
	 * @throws IOException 
	 * @see selectRelatedBrand(String brand,int beginPageNum,int pageSize)
	 */
	public List<ReleaseTB> saerchByLable(String lable,int beginPageNum,int pageSize){
		List<ReleaseTB> brandList = null;
		String sql = "select * from "+ReleaseTB.TABLE_NAME +
		" where " +ReleaseTB.RELEASE_LABLE + " = '"+lable+"'" +" order by "+ReleaseTB.RELEASE_DATE+" desc limit "+beginPageNum+","+pageSize; 
		
		if(logger.isDebugEnabled()){
			logger.debug("getUserInfoByName() sql:"+sql.toString());
		}
		
		brandList = selectReleaseListBySqlNoContent(sql);
		
		return brandList;
	}
	
	/**
	 * @version 1.0
	 * @param String brand
	 * @author Shea
	 * @return ResultSet  
	 * @throws IOException 
	 * @see selectRelatedBrand(String brand,int beginPageNum,int pageSize)
	 */
	public List<ReleaseTB> saerchAllRelease(){
		List<ReleaseTB> releaseList = null;
		String sql = "select * from "+ReleaseTB.TABLE_NAME; 
		
		if(logger.isDebugEnabled()){
			logger.debug("getUserInfoByName() sql:"+sql.toString());
		}
		
		releaseList = selectReleaseListBySql(sql);
		
		return releaseList;
	}
	
	/**
	 * @version 1.0
	 * @param String brand
	 * @author Shea
	 * @return ResultSet  
	 * @throws IOException 
	 * @see selectRelatedBrand(String brand,int beginPageNum,int pageSize)
	 */
	public List<ReleaseTB> selectReleaseListBySql(String sql){
		List<ReleaseTB> releaseList = null;
		DictionaryOS dictionaryOS= new DictionaryOS(conn);
		ResultSet resultSet = databaseConnection.executeQuery(conn, sql);
		if(resultSet != null){
				try {
					releaseList = new ArrayList<ReleaseTB>();
					while(resultSet.next()){
						ReleaseTB release = new ReleaseTB();
						release.setRelease_id(resultSet.getString(ReleaseTB.RELEASE_ID));
						release.setRelease_brand(resultSet.getString(ReleaseTB.RELEASE_BRAND));
						release.setRelease_context(resultSet.getString(ReleaseTB.RELEASE_CONTEXT));
						release.setRelease_date(resultSet.getString(ReleaseTB.RELEASE_DATE));
						release.setRelease_des(resultSet.getString(ReleaseTB.RELEASE_DES));
						release.setRelease_key(resultSet.getString(ReleaseTB.RELEASE_KEY));
						release.setRelease_lable(resultSet.getString(ReleaseTB.RELEASE_LABLE));
						
						release.setRelease_from(resultSet.getString(ReleaseTB.RELEASE_FROM));
						release.setRelease_kind(resultSet.getString(ReleaseTB.RELEASE_KIND));
						
						
						release.setRelease_md_date(resultSet.getString(ReleaseTB.RELEASE_MD_DATE));
						release.setRelease_subject(resultSet.getString(ReleaseTB.RELEASE_SUBJECT));
						release.setRelease_url(resultSet.getString(ReleaseTB.RELEASE_URL));
						release.setRelease_image(resultSet.getString(ReleaseTB.RELEASE_IMAGE)+"");
						release.setRelease_ip(resultSet.getString(ReleaseTB.RELEASE_IP));
						release.setRelease_useremail(resultSet.getString(ReleaseTB.RELEASE_USERMEAIL));
						release.setRelease_state(resultSet.getString(ReleaseTB.RELEASE_STATE));
						
						release.setRelease_bear(resultSet.getInt(ReleaseTB.RELEASE_BEAR));
						release.setRelease_replys(resultSet.getInt(ReleaseTB.RELEASE_REPLYS));
						release.setRelease_views(resultSet.getInt(ReleaseTB.RELEASE_VIEWS));
						
						release.setRelease_labledicvalue(dictionaryOS.getDictValue(release.getRelease_lable()));//为了显示
						release.setRelease_kindvalue(dictionaryOS.getDictValue(release.getRelease_kind()));//为了显示
						release.setRewriteUrl(getRewriteUrlToView(release.getRelease_id()));//为了显示
						try {
							release.setEncodebrand(java.net.URLEncoder.encode(release.getRelease_brand(),"utf-8").replaceAll("%", "%25"));
						} catch (UnsupportedEncodingException e) {
							// TODO Auto-generated catch block
							e.printStackTrace();
						}
						releaseList.add(release);
					}
					resultSet.close();
				} catch (SQLException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
		}
		
		return releaseList;
	}
	
	/**
	 * @version 1.0
	 * @param String brand
	 * @author Shea
	 * @return ResultSet  
	 * @throws IOException 
	 * @see selectRelatedBrand(String brand,int beginPageNum,int pageSize)
	 */
	public List<ReleaseTB> selectReleaseListBySqlNoContent(String sql){
		List<ReleaseTB> releaseList = null;
		DictionaryOS dictionaryOS= new DictionaryOS(conn);
		ResultSet resultSet = databaseConnection.executeQuery(conn, sql);
		if(resultSet != null){
				try {
					releaseList = new ArrayList<ReleaseTB>();
					while(resultSet.next()){
						ReleaseTB release = new ReleaseTB();
						release.setRelease_id(resultSet.getString(ReleaseTB.RELEASE_ID));
						release.setRelease_brand(resultSet.getString(ReleaseTB.RELEASE_BRAND));
						//release.setRelease_context(resultSet.getString(ReleaseTB.RELEASE_CONTEXT));
						release.setRelease_date(resultSet.getString(ReleaseTB.RELEASE_DATE));
						release.setRelease_des(resultSet.getString(ReleaseTB.RELEASE_DES));
						release.setRelease_key(resultSet.getString(ReleaseTB.RELEASE_KEY));
						release.setRelease_lable(resultSet.getString(ReleaseTB.RELEASE_LABLE));
						
						release.setRelease_from(resultSet.getString(ReleaseTB.RELEASE_FROM));
						release.setRelease_kind(resultSet.getString(ReleaseTB.RELEASE_KIND));
						
						
						release.setRelease_md_date(resultSet.getString(ReleaseTB.RELEASE_MD_DATE));
						release.setRelease_subject(resultSet.getString(ReleaseTB.RELEASE_SUBJECT));
						release.setRelease_url(resultSet.getString(ReleaseTB.RELEASE_URL));
						release.setRelease_image(resultSet.getString(ReleaseTB.RELEASE_IMAGE)+"");
						release.setRelease_ip(resultSet.getString(ReleaseTB.RELEASE_IP));
						release.setRelease_useremail(resultSet.getString(ReleaseTB.RELEASE_USERMEAIL));
						release.setRelease_state(resultSet.getString(ReleaseTB.RELEASE_STATE));
						
						release.setRelease_bear(resultSet.getInt(ReleaseTB.RELEASE_BEAR));
						release.setRelease_replys(resultSet.getInt(ReleaseTB.RELEASE_REPLYS));
						release.setRelease_views(resultSet.getInt(ReleaseTB.RELEASE_VIEWS));
						
						release.setRelease_labledicvalue(dictionaryOS.getDictValue(release.getRelease_lable()));//为了显示
						release.setRelease_kindvalue(dictionaryOS.getDictValue(release.getRelease_kind()));//为了显示
						release.setRewriteUrl(getRewriteUrlToView(release.getRelease_id()));//为了显示
						
						try {
							release.setEncodebrand(java.net.URLEncoder.encode(release.getRelease_brand(),"utf-8").replaceAll("%", "%25"));
						} catch (UnsupportedEncodingException e) {
							// TODO Auto-generated catch block
							e.printStackTrace();
						}
						
						releaseList.add(release);
					}
					resultSet.close();
				} catch (SQLException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
		}
		
		return releaseList;
	}
	
	/**
	 * @version 1.0
	 * @param String brand
	 * @author Shea
	 * @return ResultSet  
	 * @throws IOException 
	 * @see selectRelatedBrand(String brand,int beginPageNum,int pageSize)
	 */
	public List<ReleaseTB> selectReleaseListBySqlLimitContent(String sql){
		List<ReleaseTB> releaseList = null;
		DictionaryOS dictionaryOS= new DictionaryOS(conn);
		ResultSet resultSet = databaseConnection.executeQuery(conn, sql);
		if(resultSet != null){
				try {
					releaseList = new ArrayList<ReleaseTB>();
					while(resultSet.next()){
						ReleaseTB release = new ReleaseTB();
						release.setRelease_id(resultSet.getString(ReleaseTB.RELEASE_ID));
						release.setRelease_brand(resultSet.getString(ReleaseTB.RELEASE_BRAND));
						
						String content = zozopo.comm.Validate.htmlLabelFilter(resultSet.getString(ReleaseTB.RELEASE_CONTEXT));
						content = zozopo.comm.Validate.htmlFilter(content);
						
						if(content.length() >=200 ){
							content = content.substring(0, 200) + "...";
						}
						
						release.setRelease_context(content);
						
						
						release.setRelease_date(resultSet.getString(ReleaseTB.RELEASE_DATE));
						release.setRelease_des(resultSet.getString(ReleaseTB.RELEASE_DES));
						release.setRelease_key(resultSet.getString(ReleaseTB.RELEASE_KEY));
						release.setRelease_lable(resultSet.getString(ReleaseTB.RELEASE_LABLE));
						
						release.setRelease_from(resultSet.getString(ReleaseTB.RELEASE_FROM));
						release.setRelease_kind(resultSet.getString(ReleaseTB.RELEASE_KIND));
						
						
						release.setRelease_md_date(resultSet.getString(ReleaseTB.RELEASE_MD_DATE));
						release.setRelease_subject(resultSet.getString(ReleaseTB.RELEASE_SUBJECT));
						release.setRelease_url(resultSet.getString(ReleaseTB.RELEASE_URL));
						release.setRelease_image(resultSet.getString(ReleaseTB.RELEASE_IMAGE)+"");
						release.setRelease_ip(resultSet.getString(ReleaseTB.RELEASE_IP));
						release.setRelease_useremail(resultSet.getString(ReleaseTB.RELEASE_USERMEAIL));
						release.setRelease_state(resultSet.getString(ReleaseTB.RELEASE_STATE));
						
						release.setRelease_bear(resultSet.getInt(ReleaseTB.RELEASE_BEAR));
						release.setRelease_replys(resultSet.getInt(ReleaseTB.RELEASE_REPLYS));
						release.setRelease_views(resultSet.getInt(ReleaseTB.RELEASE_VIEWS));
						
						release.setRelease_labledicvalue(dictionaryOS.getDictValue(release.getRelease_lable()));//为了显示
						release.setRelease_kindvalue(dictionaryOS.getDictValue(release.getRelease_kind()));//为了显示
						release.setRewriteUrl(getRewriteUrlToView(release.getRelease_id()));//为了显示
						
						try {
							release.setEncodebrand(java.net.URLEncoder.encode(release.getRelease_brand(),"utf-8").replaceAll("%", "%25"));
						} catch (UnsupportedEncodingException e) {
							// TODO Auto-generated catch block
							e.printStackTrace();
						}
						releaseList.add(release);
					}
					resultSet.close();
				} catch (SQLException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
		}
		
		return releaseList;
	}
	
	/**
	 * @version 1.0
	 * @param String brand
	 * @author Shea
	 * @return ResultSet  
	 * @throws IOException 
	 * @see 按首字母查询
	 */
	public List<ReleaseTB> selectReleaseListByFirstCharacter(String firstChar){
		List<ReleaseTB> releaseList = null;
		String sql = "SELECT DISTINCT("+ReleaseTB.RELEASE_BRAND+") FROM "+ReleaseTB.TABLE_NAME+" WHERE "+ReleaseTB.RELEASE_KIND+" = 'KIND.RECOMMENDSTORE' and  UPPER(SUBSTRING("+ReleaseTB.RELEASE_BRAND+" , 1 , 1)) = '"+firstChar+"'";
		ResultSet resultSet = databaseConnection.executeQuery(conn, sql);
		if(resultSet != null){
				try {
					releaseList = new ArrayList<ReleaseTB>();
					while(resultSet.next()){
						ReleaseTB release = new ReleaseTB();
						//release.setRelease_id(resultSet.getString(ReleaseTB.RELEASE_ID));
						release.setRelease_brand(resultSet.getString(ReleaseTB.RELEASE_BRAND));
						
						try {
							release.setEncodebrand(java.net.URLEncoder.encode(release.getRelease_brand(),"utf-8").replaceAll("%", "%25"));
						} catch (UnsupportedEncodingException e) {
							// TODO Auto-generated catch block
							e.printStackTrace();
						}
						releaseList.add(release);
					}
					resultSet.close();
				} catch (SQLException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
		}
		
		return releaseList;
	}
	
	/**
	 * @version 1.0
	 * @param String brand
	 * @author Shea
	 * @return ResultSet  
	 * @throws IOException 
	 * @see selectRelatedBrand(String brand,int beginPageNum,int pageSize)
	 */
	public List<ReleaseTB> selectReleaseListByResultSet(ResultSet resultSet){
		List<ReleaseTB> releaseList = null;
		DictionaryOS dictionaryOS= new DictionaryOS(conn);
	
		if(resultSet != null){
				try {
					releaseList = new ArrayList<ReleaseTB>();
					while(resultSet.next()){
						ReleaseTB release = new ReleaseTB();
						release.setRelease_id(resultSet.getString(ReleaseTB.RELEASE_ID));
						release.setRelease_brand(resultSet.getString(ReleaseTB.RELEASE_BRAND));
						release.setRelease_context(resultSet.getString(ReleaseTB.RELEASE_CONTEXT));
						release.setRelease_date(resultSet.getString(ReleaseTB.RELEASE_DATE));
						release.setRelease_des(resultSet.getString(ReleaseTB.RELEASE_DES));
						release.setRelease_key(resultSet.getString(ReleaseTB.RELEASE_KEY));
						release.setRelease_lable(resultSet.getString(ReleaseTB.RELEASE_LABLE));
						
						release.setRelease_from(resultSet.getString(ReleaseTB.RELEASE_FROM));
						release.setRelease_kind(resultSet.getString(ReleaseTB.RELEASE_KIND));
						
						
						release.setRelease_md_date(resultSet.getString(ReleaseTB.RELEASE_MD_DATE));
						release.setRelease_subject(resultSet.getString(ReleaseTB.RELEASE_SUBJECT));
						release.setRelease_url(resultSet.getString(ReleaseTB.RELEASE_URL));
						release.setRelease_ip(resultSet.getString(ReleaseTB.RELEASE_IP));
						release.setRelease_useremail(resultSet.getString(ReleaseTB.RELEASE_USERMEAIL));
						release.setRelease_state(resultSet.getString(ReleaseTB.RELEASE_STATE));
						
						release.setRelease_bear(resultSet.getInt(ReleaseTB.RELEASE_BEAR));
						release.setRelease_replys(resultSet.getInt(ReleaseTB.RELEASE_REPLYS));
						release.setRelease_views(resultSet.getInt(ReleaseTB.RELEASE_VIEWS));
						
						release.setRelease_labledicvalue(dictionaryOS.getDictValue(release.getRelease_lable()));//为了显示
						release.setRelease_kindvalue(dictionaryOS.getDictValue(release.getRelease_kind()));//为了显示
						release.setRewriteUrl(getRewriteUrlToView(release.getRelease_id()));//为了显示
						try {
							release.setEncodebrand(java.net.URLEncoder.encode(release.getRelease_brand(),"utf-8").replaceAll("%", "%25"));
						} catch (UnsupportedEncodingException e) {
							// TODO Auto-generated catch block
							e.printStackTrace();
						}
						releaseList.add(release);
					}
					resultSet.close();
				} catch (SQLException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
		}
		
		return releaseList;
	}
	
	/**
	 * @version 1.0
	 * @param String brand
	 * @author Shea
	 * @return ResultSet  
	 * @throws IOException 
	 * @see selectRelatedBrand(String brand,int beginPageNum,int pageSize)
	 */
	public boolean deleteSubject(int id){
		SqlMachine sqlMachine = new SqlMachine(conn);
		return sqlMachine.deleteRow(ReleaseTB.TABLE_NAME, ReleaseTB.RELEASE_ID, id);
	}
	
	public void views(int id){
		String sql = "update "+ReleaseTB.TABLE_NAME+" set " +ReleaseTB.RELEASE_VIEWS + " = " + ReleaseTB.RELEASE_VIEWS + "+1 where "+ ReleaseTB.RELEASE_ID + " = " +id;
		databaseConnection.executeUpdate(conn, sql);
	}
	
	public void reply(int id){
		String sql = "update "+ReleaseTB.TABLE_NAME+" set " +ReleaseTB.RELEASE_REPLYS + " = " + ReleaseTB.RELEASE_REPLYS + "+1 where "+ ReleaseTB.RELEASE_ID + " = " +id;
		databaseConnection.executeUpdate(conn, sql);
	}
	
	public boolean bear(int id){
		String sql = "update "+ReleaseTB.TABLE_NAME+" set " +ReleaseTB.RELEASE_BEAR + " = " + ReleaseTB.RELEASE_BEAR + "+1 where "+ ReleaseTB.RELEASE_ID + " = " +id;
		return databaseConnection.executeUpdate(conn, sql);
	}
	
	
	/**
	 * @version 1.0
	 * @param ReleaseTB release
	 * @author Shea
	 * @return boolean  
	 * @throws IOException 
	 * @see insertRelease(ImageTB image)
	 */
	public int getRowNum(){
		int rowNum = 0;
		String sql = "select count(*) as rowNum from " + ReleaseTB.TABLE_NAME ;
		
		ResultSet resultSet = databaseConnection.executeQuery(conn, sql);
		if(resultSet != null){
			try {
				
				while(resultSet.next()){
					rowNum = resultSet.getInt("rowNum");
				}
				resultSet.close();
			} catch (SQLException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}
		
		return rowNum;
	}
	
	/**
	 * @version 1.0
	 * @param ReleaseTB release
	 * @author Shea
	 * @return boolean  
	 * @throws IOException 
	 * @see insertRelease(ImageTB image)
	 */
	public int getRowNumByBrand(String brand){
		int rowNum = 0;
		String sql = "select count(*) as rowNum from " + ReleaseTB.TABLE_NAME +
		" where " +ReleaseTB.RELEASE_BRAND + " like '%"+brand+"%'";
		
		ResultSet resultSet = databaseConnection.executeQuery(conn, sql);
		if(resultSet != null){
			try {
				
				while(resultSet.next()){
					rowNum = resultSet.getInt("rowNum");
				}
				resultSet.close();
			} catch (SQLException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}
		
		return rowNum;
	}
	
	/**
	 * @version 1.0
	 * @param ReleaseTB release
	 * @author Shea
	 * @return boolean  
	 * @throws IOException 
	 * @see insertRelease(ImageTB image)
	 */
	public int getRowNumByUsermail(String usermail){
		int rowNum = 0;
		String sql = "select count(*) as rowNum from " + ReleaseTB.TABLE_NAME +
		" where " +ReleaseTB.RELEASE_USERMEAIL + " = '"+usermail+"'";
		
		ResultSet resultSet = databaseConnection.executeQuery(conn, sql);
		if(resultSet != null){
			try {
				
				while(resultSet.next()){
					rowNum = resultSet.getInt("rowNum");
				}
				resultSet.close();
			} catch (SQLException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}
		
		return rowNum;
	}
	
	/**
	 * @version 1.0
	 * @param ReleaseTB release
	 * @author Shea
	 * @return boolean  
	 * @throws IOException 
	 * @see insertRelease(ImageTB image)
	 */
	public int getRowNumBySubject(String subject){
		int rowNum = 0;
		String sql = "select count(*) as rowNum from " + ReleaseTB.TABLE_NAME +
		" where " +ReleaseTB.RELEASE_SUBJECT + " like '%"+subject+"%'";
		
		ResultSet resultSet = databaseConnection.executeQuery(conn, sql);
		if(resultSet != null){
			try {
				
				while(resultSet.next()){
					rowNum = resultSet.getInt("rowNum");
				}
				resultSet.close();
			} catch (SQLException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}
		
		return rowNum;
	}
	
	/**
	 * @version 1.0
	 * @param ReleaseTB release
	 * @author Shea
	 * @return boolean  
	 * @throws IOException 
	 * @see 获取类型行数
	 */
	public int getRowNumByKind(String kind){
		int rowNum = 0;
		String sql = "select count(*) as rowNum from " + ReleaseTB.TABLE_NAME +
		" where " +ReleaseTB.RELEASE_KIND + " = '"+kind+"'";
		
		ResultSet resultSet = databaseConnection.executeQuery(conn, sql);
		if(resultSet != null){
			try {
				
				while(resultSet.next()){
					rowNum = resultSet.getInt("rowNum");
				}
				resultSet.close();
			} catch (SQLException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}
		
		return rowNum;
	}
	
	/**
	 * @version 1.0
	 * @param ReleaseTB release
	 * @author Shea
	 * @return boolean  
	 * @throws IOException 
	 * @see insertRelease(ImageTB image)
	 */
	public int getRowNumByLable(String lable){
		int rowNum = 0;
		String sql = "select count(*) as rowNum from " + ReleaseTB.TABLE_NAME +
		" where " +ReleaseTB.RELEASE_LABLE + " = '"+lable+"'";
		
		ResultSet resultSet = databaseConnection.executeQuery(conn, sql);
		if(resultSet != null){
			try {
				
				while(resultSet.next()){
					rowNum = resultSet.getInt("rowNum");
				}
				resultSet.close();
			} catch (SQLException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}
		
		return rowNum;
	}
	
	/**
	 * @version 1.0
	 * @param ReleaseTB release
	 * @author Shea
	 * @return boolean  
	 * @throws IOException 
	 * @see insertRelease(ImageTB image)
	 */
	public int getRowNumByDistBrandAndLable(String lable){
		int rowNum = 0;
		String sql = "select count(DISTINCT "+ReleaseTB.RELEASE_BRAND+") as rowNum from " + ReleaseTB.TABLE_NAME +
		" where " +ReleaseTB.RELEASE_LABLE + " = '"+lable+"'";
		
		ResultSet resultSet = databaseConnection.executeQuery(conn, sql);
		if(resultSet != null){
			try {
				
				while(resultSet.next()){
					rowNum = resultSet.getInt("rowNum");
				}
				resultSet.close();
			} catch (SQLException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}
		
		return rowNum;
	}
	
	
	
	/**
	 * @version 1.0
	 * @param ReleaseTB release
	 * @author Shea
	 * @return boolean  
	 * @throws IOException 
	 * @see insertRelease(ImageTB image)
	 */
	public int getRowNumByBrandAndLable(String rrand,String lable){
		int rowNum = 0;
		String sql = "select count(*) as rowNum from " + ReleaseTB.TABLE_NAME +
		" where " +ReleaseTB.RELEASE_LABLE + " = '"+lable+"' and " + ReleaseTB.RELEASE_BRAND + " like'%"+rrand+"%' ";
		
		ResultSet resultSet = databaseConnection.executeQuery(conn, sql);
		if(resultSet != null){
			try {
				
				while(resultSet.next()){
					rowNum = resultSet.getInt("rowNum");
				}
				resultSet.close();
			} catch (SQLException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}
		
		return rowNum;
	}
	
	/**
	 * @version 1.0
	 * @param ReleaseTB release
	 * @author Shea
	 * @return boolean  
	 * @throws IOException 
	 * @see insertRelease(ImageTB image)
	 */
	public int getRowNumByBrandAndKind(String Brand,String kind){
		int rowNum = 0;
		String sql = "select count(*) as rowNum from " + ReleaseTB.TABLE_NAME +
		" where " +ReleaseTB.RELEASE_KIND + " = '"+kind+"' and " + ReleaseTB.RELEASE_BRAND + "like'%"+Brand+"%'";
		
		ResultSet resultSet = databaseConnection.executeQuery(conn, sql);
		if(resultSet != null){
			try {
				
				while(resultSet.next()){
					rowNum = resultSet.getInt("rowNum");
				}
				resultSet.close();
			} catch (SQLException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}
		
		return rowNum;
	}
	
	/**
	 * @version 1.0
	 * @param ReleaseTB release
	 * @author Shea
	 * @return boolean  
	 * @throws IOException 
	 * @see insertRelease(ImageTB image)
	 */
	public int getRowNumByBrandAndKindAndLable(String Brand,String kind,String lable){
		int rowNum = 0;
		String sql = "select count(*) as rowNum from " + ReleaseTB.TABLE_NAME +
		" where " +ReleaseTB.RELEASE_KIND + " = '"+kind+"' and " + ReleaseTB.RELEASE_BRAND + "like'%"+Brand+"%'" + 
		"and " + ReleaseTB.RELEASE_LABLE + " = '"+lable+"'";
		
		ResultSet resultSet = databaseConnection.executeQuery(conn, sql);
		if(resultSet != null){
			try {
				
				while(resultSet.next()){
					rowNum = resultSet.getInt("rowNum");
				}
				resultSet.close();
			} catch (SQLException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}
		
		return rowNum;
	}
	
	/**
	 * @version 1.0
	 * @param 
	 * @author Shea
	 * @return boolean  
	 * @throws IOException 
	 * @see 判断URL是已经存在
	 */
	
	public boolean isExistUrl(String url){
		boolean eResult = false;
		
		String sql = "select * from "+ReleaseTB.TABLE_NAME+" where "+ReleaseTB.RELEASE_URL+"='"+url+"'";
		
		//System.out.println(sql);
		if(logger.isDebugEnabled()){
			logger.debug("isExist() sql:"+sql.toString());
		}
		try {
			ResultSet result = databaseConnection.executeQuery(conn,sql);
		
			if(result.next()){
				eResult = true;
			}
			result.close();
		} catch (SQLException e) {
			e.printStackTrace();
		}
		return eResult;
	}
	
	/**
	 * @version 1.0
	 * @param 
	 * @author Shea
	 * @return boolean  
	 * @throws IOException 
	 * @see URL重写 解析
	 */
	
	public static String getRewriteUrl(String url) { 

		int iIndex = url.lastIndexOf("/");
		int pointIndex = url.lastIndexOf(".");
		
		String headStr = url.substring(0, iIndex);
		String lastStr = url.substring(iIndex+1, pointIndex);
		
		String[] str = lastStr.split("_");
		
		StringBuffer retStr = new StringBuffer();
		retStr.append(headStr);
		retStr.append("/");
		retStr.append(str[0]);
		retStr.append(".action?");
		retStr.append(str[1]);
		retStr.append("=");
		retStr.append(str[2]);
			
		//headStr + "/"+str[0]+".action?"+str[1]+"=" + str[2];
		
		return retStr.toString();

	}
	
	/**
	 * @version 1.0
	 * @param 
	 * @author Shea
	 * @return boolean  
	 * @throws IOException 
	 * @see URL重写 显示
	 */
	public static String getRewriteUrlToView(String id) { 
		StringBuffer retStr = new StringBuffer();
		retStr.append("view_id_");
		retStr.append(id);
		retStr.append(".html");
			
		return retStr.toString();
	}
	
	
	/**
	 * @version 1.0
	 * @param 
	 * @author Shea
	 * @return boolean  
	 * @throws IOException 
	 * @see 显示标签
	 */
	public Map<String,Integer> selectBrandTag(int beginPageNum,int pageSize) { 
		String sql = "SELECT COUNT("+ReleaseTB.RELEASE_BRAND+")as rowNum,MAX("+ReleaseTB.RELEASE_BRAND+") as "+ReleaseTB.RELEASE_BRAND+" FROM "+ReleaseTB.TABLE_NAME+" GROUP BY "+ReleaseTB.RELEASE_BRAND+" HAVING COUNT("+ReleaseTB.RELEASE_BRAND+")>1 "
		+" limit "+beginPageNum+","+pageSize; 
		ResultSet resultSet = databaseConnection.executeQuery(conn,sql);
		
		Map<String,Integer> brandTag = null;
		
		if(resultSet != null){
			try {
				brandTag = new HashMap<String,Integer>();
				while(resultSet.next()){
					brandTag.put(resultSet.getString(ReleaseTB.RELEASE_BRAND),resultSet.getInt("rowNum"));
				}
				resultSet.close();
			} catch (SQLException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
	}
		
		return brandTag;
	}
}
